﻿
#pragma  once
#ifndef _VIDEO_PS_H_
#define _VIDEO_PS_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif


#define GetY(R,G,B) (0.299*(R)+0.587*(G)+0.114*(B)+16)
#define GetU(R,G,B) (-0.147*(R)-0.289*(G)+0.436*(B)+128)
#define GetV(R,G,B) (0.615*(R)-0.515*(G)-0.100*(B)+128)

#define SOBEL_SIZE 3
#define NUMROWS 720
#define NUMCOLS 1280
#define YUV_BLACK_VAL 0x80
#define BYTESHIFT 8

typedef struct
{
    //unsigned short    bfType;
    unsigned long    bfSize;
    unsigned short    bfReserved1;
    unsigned short    bfReserved2;
    unsigned long    bfOffBits;
} ClBitMapFileHeader;

typedef struct
{
    unsigned long  biSize;
    long   biWidth;
    long   biHeight;
    unsigned short   biPlanes;
    unsigned short   biBitCount;
    unsigned long  biCompression;
    unsigned long  biSizeImage;
    long   biXPelsPerMeter;
    long   biYPelsPerMeter;
    unsigned long   biClrUsed;
    unsigned long   biClrImportant;
} ClBitMapInfoHeader;

typedef struct
{
    unsigned char rgbBlue; //该颜色的蓝色分量
    unsigned char rgbGreen; //该颜色的绿色分量
    unsigned char rgbRed; //该颜色的红色分量
    unsigned char rgbReserved; //保留值
} ClRgbQuad;

typedef struct
{
    int width;
    int height;
    int channels;
    unsigned char* imageData;
}ClImage;

typedef struct image{
	unsigned char	*im;
	int     dims[2];
}image;

typedef union _Tu8u16_
{
	uint8_t		u8[2];
	uint16_t	u16;
}u8u16_t;

//extern void yuv420pToYuv422Packed(unsigned char *pyuv422, unsigned char *pyuv420, int width, int height);
extern void rgb2yuv422Packed(unsigned char rgbData[1280*720*3], unsigned short yuvData[1280*720]);
extern unsigned char* clLoadImage(char* path);
//extern void sobel_filter(unsigned short yc_in[NUMROWS*NUMCOLS],unsigned short yc_out[NUMROWS*NUMCOLS]);
//extern unsigned char sobel_operator(unsigned char window[SOBEL_SIZE][SOBEL_SIZE]);

void image_zoom_out_2x2_1280_kernel(unsigned char *pdst_img, unsigned char *psrc_img, int image_w, int image_h);
//void image_zoom_out_2x2_1280_kernel(unsigned char pdst_img[640 * 360], unsigned char psrc_img[1280 * 720]);

void image_zoom_out_2x2_1280_kernel_u16(uint8_t *pdst_img, uint16_t *psrc_img, int image_h);

void image_zoom_out_2x2_1280_kernel_u16_2(uint8_t *pdst_img, u8u16_t *psrc_img, int image_h);

void image_zoom_out_2x2_1280(unsigned char pdst_img[640 * 360], unsigned char psrc_img[1280 * 720]);

void image_zoom_out_2x2_kernel(unsigned char *pdst_img, unsigned char *psrc_img, int image_w, int image_h);

void ldw_get_lane_mask_PL(unsigned char * p_src_img, unsigned char * p_edge_img,
	unsigned char threshold, unsigned char lane_w, int image_w, int image_h/*, int vanish_line*/);

//void ldw_get_lane_mask0_1(unsigned char * p_src_img, unsigned char * p_edge_img, 
//	unsigned char threshold, unsigned char lane_w, int image_w, int image_h, int vanish_line);
extern void ldw_get_lane_mask_(unsigned char * p_src_img, unsigned char * p_edge_img, 
	unsigned char threshold, unsigned char lane_w, int image_w, int image_h, int vanish_line);

void ldw_dilation_filter_opt_kernel(unsigned char *psrc_img, unsigned char *pdst_img, int image_w, int image_h);
void dilation_filter_opt_ldw_0(unsigned char *psrc_img, unsigned char *pbuffer, int width, int height);


void edge_filter_x_kernel(uint8_t *pdst_img, uint8_t *psrc_img,
	int thin_proc_img_h, uint16_t top_cut_h, uint16_t cut_h_factor);

#ifdef __cplusplus
}
#endif


#endif		// end: _VIDEO_PS_H_
